package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import com.spzx.product.service.CategoryService;
import com.spzx.product.service.impl.CategoryServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-07-22
 */
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {

    @Autowired
    private CategoryBrandService categoryBrandService;
    @Operation(summary = "品牌列表分页")
    @GetMapping("/list")
    public TableDataInfo list(){
        startPage();
        List<CategoryBrand> list = categoryBrandService.selectCategoryBrandList();
        return getDataTable(list);
    }



    @Operation(summary = "添加品牌列表")
    @PostMapping
    public AjaxResult add(@RequestBody CategoryBrand categoryBrand) {
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        return success(categoryBrandService.addCategoryBrand(categoryBrand));
    }

    @Operation(summary = "删除分类品牌")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @Parameter(description = "分类品牌id列表", example = "[1,2]")
            @PathVariable List<Long> ids) {
        return toAjax(categoryBrandService.removeBatchByIds(ids));
    }
}
